#include <stdio.h>
#include <unistd.h>
#include "rectangle.h"

int draw_rectangle_menu(void)
{
	printf ("----------------DrawRectangle------------\r\n");
	printf ("1. Draw Rectangle to rgb raw file\r\n");
	printf ("2. Draw Rectangle to console\r\n");
	printf ("3. Draw Rectangle to jpeg file\r\n");
	printf ("4. Draw Rectangle to BMP file\r\n");
	printf ("5. Draw Rectangle to yuv raw file\r\n");
	printf ("0. Exit\r\n");
	printf ("Select:");
}

void draw_rectangle_read_input(struct rectangle *in)
{
	printf ("Enter X1:");
	scanf ("%d",&in->x1);
	printf ("Enter Y1:");
	scanf ("%d",&in->y1);
	printf ("Enter X2:");
	scanf ("%d",&in->x2);
	printf ("Enter Y2:");
	scanf ("%d",&in->y2);
	printf ("Enter Thickness:");
	scanf ("%d",&in->line_thickness);
	printf ("Enter Color [RGB:(0x00XXXXXX)]:");
	scanf ("%x",&in->line_color);
	printf ("Enter Background Color [RGB:(0x00XXXXXX)]:");
	scanf ("%x",&in->bg_color);
	printf ("Enter Plane X res:");
	scanf ("%d",&in->x_res);
	printf ("Enter Plane Y res:");
	scanf ("%d",&in->y_res);
}

int draw_rectangle_process_request (char cmd)
{
	int ret = -1;
	struct rectangle input; 

	switch (cmd) 
	{
		case '1':
			draw_rectangle_read_input (&input);
			printf ("Enter File path:");
			scanf ("%s",input.file);
			draw_rectangle_raw_rgb_image_file (&input);
		break;
		case '2':
			draw_rectangle_read_input (&input);
			ret = draw_rectangle_to_console (&input);
		break;
		case '3':
		break;
		case '4':
			draw_rectangle_read_input (&input);
			printf ("Enter File path:");
			scanf ("%s",input.file);
			draw_rectangle_bmp_image_file (&input);
		break;
		case '5':
			draw_rectangle_read_input (&input);
			printf ("Enter File path:");
			scanf ("%s",input.file);
			printf ("Enter YUV Format:");
			scanf ("%d",&input.yuv_format);
			ret = draw_rectangle_raw_yuv_image_file (&input);
		break;
		case '0':
			exit (0);
		default:
		break;
	}
	return ret;	
}

int main (void)
{
	char q;

	do {
		q = '0';
		draw_rectangle_menu ();
		q = getc (stdin);
		getchar ();

		draw_rectangle_process_request(q);
	} while (q != '0');
	return 0;	
}
